package concurrent.completationstage;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import org.testng.annotations.Test;

/**
 * get和join方法
 *
 * @author zhang peipei
 */
public class Completation2 {


    public static void main(String[] args) throws ExecutionException, InterruptedException {

    }

    @Test(description = "unchecked exception不需要主动处理")
    private void t1() {
        CompletableFuture<Integer> f1 = CompletableFuture.supplyAsync(() -> {
            int i = 1/1;
            return 1;
        });

        // 有无必要使用这种方式？
        CompletableFuture.allOf(f1).join();
        var res = f1.join();
        System.out.println("CompletableFuture Test res " + res);
    }


    @Test(description = "区别就是需要主动处理异常，checked exception需要主动处理")
    private void t2() throws ExecutionException, InterruptedException {
        CompletableFuture<Integer> f1 = CompletableFuture.supplyAsync(() -> {
            int i = 1/0;
            return 1;
        });

        f1.get();
        System.out.println("CompletableFuture Test");
    }

}
